//
//  CellForVC2.m
//  PCAForWar
//
//  Created by dllo on 16/1/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellForVC2.h"
#import "ModelForVC2.h"
#import <DKNightVersion.h>

@implementation CellForVC2

- (void)dealloc{
    
    [_labelTitle release];
    [_labelGaiYao release];
    [_labelComment release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createSubView];
        [self Night];
        
    }
    return self;
}

#pragma mark 夜间模式
- (void)Night {
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    
    self.labelTitle.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelGaiYao.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelComment.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
}

- (void)createSubView {
    
    /** labelTitle */
    self.labelTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelTitle];
    
    self.labelTitle.font = [UIFont boldSystemFontOfSize:18];
    
    /** labelGaiYao */
    self.labelGaiYao = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelGaiYao];
    
    self.labelGaiYao.numberOfLines = 0;
    self.labelGaiYao.font = [UIFont systemFontOfSize:14];
    self.labelGaiYao.lineBreakMode = NSLineBreakByCharWrapping;
    
    /** labelComment */
    self.labelComment = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelComment];
    
    self.labelComment.layer.cornerRadius = 8;
    self.labelComment.layer.masksToBounds = YES;
    self.labelComment.font = [UIFont systemFontOfSize:12];
    self.labelComment.textAlignment = NSTextAlignmentCenter;
    self.labelComment.layer.borderColor = [[UIColor redColor]CGColor];
    self.labelComment.layer.borderWidth = 1.0f;
    self.labelComment.layer.masksToBounds = YES;
    
    
    [_labelTitle release];
    [_labelGaiYao release];
    [_labelComment release];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.labelTitle.frame = CGRectMake(5, 10, self.frame.size.width, (self.frame.size.height - 40)/2);
    
    self.labelGaiYao.frame = CGRectMake(5, 10 + (self.frame.size.height - 30)/2, self.frame.size.width, self.frame.size.height/2);
    
    self.labelComment.frame = CGRectMake(self.frame.size.width / 5 * 4, 77, 60, 17);
    
    
}

- (void)passModel:(ModelForVC2 *)model {
    
    self.labelTitle.text = model.Title;
    
    if (model.NewsSummary.length <= 40) {
        
        self.labelGaiYao.text = model.NewsSummary;
        
    } else {
        
        NSRange range = NSMakeRange(0,40);
        
        self.labelGaiYao.text = [model.NewsSummary substringWithRange:range];
        
    }
    self.labelComment.text = [NSString stringWithFormat:@"%@条评论",model.NewsCommentNum];
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
